﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using Models;
using SCADA.Drive;
using SIE.SCADA.SqlSugar;
using SIE.SCADA.ZemtDemo.Common;
using SIE.SCADA.ZemtDemo.Machines;
using SysManage.User;
using SIE.SCADA.Common.Log;
using System.Reflection;
using Model.Core;
using Newtonsoft.Json;
using SIE.SCADA.ZemtDemo.View;
using System.Windows;
using SCADA_DAQ.ZEMT.Server;

namespace SIE.SCADA.ZemtDemo.ViewModel
{
    /// <summary>
    /// 扭力扳手主站与从站工作交互逻辑说明
    /// 1.客户端扫码登陆操作员
    /// 2.客户端扫码派工件
    /// 3.客户端扫码序列号
    /// 4.服务端获取数据列表后，生产单内容下发到客户端
    /// 5.客户端拧紧采集后，发数据到服务器，成功跳到下一条，失败缓存
    /// 6.取消当前任务单需在服务器操作切换工件，否则会锁定
    /// </summary>
    class TorqueWrench : BaseMachine
    {
        private scada_equipment _equipment;
        //private scada_equipment device;
        //private Sys_User_UserInfo _user;
        private Sys_User_UserInfo _user = new Sys_User_UserInfo();
     
      
        //private smdc_disid_t _woInfo;
        private string _barcode;
        private scada_product_info _prod;
        private scada_process_record _curProcessRecord;
        private List<scada_process> _curProcessList;

        private bool IsLogin;

        //常量
        private const string logout_S = "SMDC0002";
        private const string clearCurWork_S = "SMDC0005";
        private const string offline_S = "SMDC0001";
        private const string reProcess_S = "SMDC0010";
        private const string monitorProcess_S = "SMDC0011";

        //是否为重打
        private bool _retryFlag = false;

        private bool _processFlag = false;

        //订单号
        private string _poid = "";




        public TorqueWrench(string machineID) : base(machineID)
        {
            WoInfoViewModel = new WoInfoViewModel();
            Message = new Message();


            //查询设备信息
            _equipment = SubmitDB.Query_scada_equipment(_deviceID);

            //工位框赋值
            WorkbinName = _equipment.workbinname;

            //默认用户
            _user.userid_int = "Z0SMDC0001";


            //connectionStatus = "True";



        }

        protected override void RegValueChanged(object sender, RegValueChangedEventArgs e)
        {
            new Thread((s) =>
            {
            }).Start(sender);
        }

        /// <summary>
        /// 处理“扫描枪”请求
        /// </summary>
        /// <returns></returns>
        public OrderMsg RequestWoInfo(string value)
        {
            ScanMsg = value;

            OrderMsg orderMsg = new OrderMsg();
            if (value == logout_S)
            {
                IsLogin = false;
                Userid = "";
                _user = null;
                Clear();

                orderMsg.Error = false;
                orderMsg.ErrorMsg = "用户退出！";
                RefreshMessage("用户退出！", MessageState.Normal);
                return orderMsg;

            }

            if (value.StartsWith("Z0") || value.StartsWith("W0"))
            {
                if (!Login(value))
                {
                    orderMsg.Error = true;
                    orderMsg.ErrorMsg = "用户登录失败!";
                    RefreshMessage("用户登录失败！", MessageState.Normal);
                    return orderMsg;
                }
                else
                {
                    Clear();
                    orderMsg.Error = false;
                    orderMsg.ErrorMsg = "用户登录成功!";
                    RefreshMessage("用户登录成功！", MessageState.Normal);
                    return orderMsg;

                }

            }

            if (_equipment == null)
            {
                orderMsg.Error = true;
                orderMsg.ErrorMsg = "没找到对应设备！";
                RefreshMessage("没找到对应设备！", MessageState.Normal);
                return orderMsg;
            }
            if (_equipment.state != "10")
            {
                RefreshMessage("设备异常！", MessageState.Normal);
                orderMsg.Error = true;
                orderMsg.ErrorMsg = "设备异常！";
                return orderMsg;
            }


            if (IsLogin)
            {
                var msg = Read_ScanNO(value);
                return msg;
            }
            else
            {

                orderMsg.Error = true;
                RefreshMessage("用户未登录！", MessageState.Normal);
                orderMsg.ErrorMsg = "用户未登录！";
                return orderMsg;
            }


        }

        /// <summary>
        /// 读单处理
        /// </summary>
        /// <param name=""></param>
        public OrderMsg Read_ScanNO(string ScanInfo)
        {
            //ScanMsg = no;
            //retryFlag = false;

            OrderMsg orderMsg = new OrderMsg();

            Logger.Info("接收到客户端（" + _equipment?.equipmentid + "）条码：" + ScanInfo);

            if (ScanInfo == null || ScanInfo == "")
            {
                Logger.Info("输入条码为空，" + _equipment?.equipmentid);
                RefreshMessage("输入条码为空！", MessageState.Normal);
                orderMsg.Error = true;
                return orderMsg;

            }

            //工件清除
            if (ScanInfo == clearCurWork_S)
            {
                if (_prod != null)
                {
                    _prod.state_int = (int)State.Failed;
                    SubmitDB.Submit_Prod(_prod);
                }
                Clear();
                Logger.Info("工件清除（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                RefreshMessage("工件清除！", MessageState.Normal);
                orderMsg.Error = false;
                return orderMsg;
            }

            if (_prod != null)
            {
                if (!ScanInfo.StartsWith("M"))
                {
                    RefreshMessage("工件正在进行中！（" + _equipment?.equipmentid + "）", MessageState.Normal);
                    Logger.Info("工件正在进行中（" + _equipment?.equipmentid + "）" );
                    orderMsg.Error = true;
                    return orderMsg;
                }
                //else
                //{

                //    _prod.state_int = (int)State.Failed;
                //    SubmitDB.Submit_Prod(_prod);
                //    Clear();

                //}
            }
            //监造
            if (ScanInfo == monitorProcess_S)
            {
                _processFlag = true;
                Logger.Info("监造（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                RefreshMessage("监造！", MessageState.Normal);
                orderMsg.Error = false;
                return orderMsg;
            }

            if (_processFlag) {
                _poid = ScanInfo;
                _processFlag = false;
                Logger.Info("监造：扫描订单号（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                RefreshMessage("监造：扫描订单号！", MessageState.Normal);
                orderMsg.Error = false;
                return orderMsg;
            }

            //重打
            if (ScanInfo == reProcess_S)
            {
                _retryFlag = true;
                Logger.Info("工序重打（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                RefreshMessage("工序重打！", MessageState.Normal);
                orderMsg.Error = false;
                return orderMsg;
            }

            //单打
            if (ScanInfo.StartsWith("M"))
            {
                if (_prod == null)
                {

                    Logger.Info("请先扫描工件条码（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                    RefreshMessage("请先扫描工件条码！", MessageState.Normal);

                    orderMsg.Error = true;
                    return orderMsg;

                }
                else
                {

                    if (_prod.state_int == (Int32)State.Wait)
                    {

                        _prod.remark_str = "单枪";
                        SubmitDB.Submit_Prod(_prod);
                        Logger.Info("单枪重打（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                        RefreshMessage("单枪重打！", MessageState.Normal);
                        orderMsg.Cur_Prod = _prod;
                        orderMsg.barcode = ScanInfo;
                        orderMsg.Error = false;
                        return orderMsg;
                    }
                    else {
                        Logger.Info("当前工件正在进行中（" + _equipment?.equipmentid + "） ScanInfo:" + ScanInfo);
                        RefreshMessage("当前工件正在进行中！", MessageState.Normal);

                        orderMsg.Error = true;
                        return orderMsg;

                    }
                }
            }
            


            _barcode = ScanInfo;
            CheckBarcode barcodeInfo = Trackin.GetListBarcodeInfo(ScanInfo);

            string MatId;
            string ProductId;
            string SN = barcodeInfo.SerialNumber;
            string RepairCode = barcodeInfo.RepairNumber;
            if (barcodeInfo.ModeNumber != null && barcodeInfo.ModeNumber.Contains("/"))
            {
                ProductId = barcodeInfo.ModeNumber;
                MatId = QueryData.GetMatidByProductid(barcodeInfo.ModeNumber).matid;
            }
            else
            {
                MatId = barcodeInfo.ModeNumber;
                ProductId = QueryData.GetMatidByProductid(barcodeInfo.ModeNumber).productid;

            }



            //物料的工序配置
            scada_process choseProcess0 = QueryData.GetProcessBySubMatIdAndEquipment(MatId, _equipment.equipmentid);
            if (choseProcess0 == null)
            {
                RefreshMessage("未找到该物料的工序配置！ 物料号：" + _prod?.matid, MessageState.Normal);
                Logger.Info("未找到该物料的工序配置！(" + _equipment?.equipmentid + "） 物料号：:" + _prod?.matid);
                orderMsg.Error = true;
                return orderMsg;
            }


            scada_product_info NewProduct = new scada_product_info();
            
            NewProduct.poid = _poid;                    
            NewProduct.productid = ProductId;
            NewProduct.matid = MatId;
            NewProduct.repaircode = RepairCode;
            NewProduct.serial_number = SN;
            NewProduct.workseqgroup = _equipment.processGroupcode;
            NewProduct.workseqgroupdesc = _equipment.processGroupcodeDesc;
            NewProduct.createtime_dt = DateTime.Now;
            NewProduct.begintime = DateTime.Now;
            NewProduct.workbin = _equipment.workbin;
            NewProduct.workbinname = _equipment.workbinname;
            NewProduct.torquetimes = choseProcess0.torquetimes;
            NewProduct.curtimes = 0;
            NewProduct.state_int = (Int32)State.Wait;
            NewProduct.userid = _user.userid_int;
            NewProduct.equipmentid = _equipment.equipmentid;
            if (_processFlag)
            {
                NewProduct.processtype = "监造";
                _poid = "";
                

            }
            else {
                NewProduct.processtype = "新造";
            }

            

            if (_retryFlag)
            {
                NewProduct.remark_str = "重打";
                _retryFlag = false;

            }

            var prodid = SubmitDB.InsertProductInfo(NewProduct);
            if (prodid == 0)
            {
                RefreshMessage("新增工件，失败！", MessageState.Normal);
                Logger.Info("新增工件,失败（" + _equipment?.equipmentid + ")");
                orderMsg.Error = true;
                return orderMsg;

            }

            //var prod3 = QueryData.GetProdInfoByMatidAndSn(MatId, SN, _equipment.processGroupcode, RepairCode).First();
            var prod3 = QueryData.GetProdInfo(prodid).First();
            if (prod3 != null)
            {
                _prod = prod3;
                RefreshMessage("获取工件，成功！", MessageState.Normal);
                Logger.Info("获取工件，成功（" + _equipment?.equipmentid + "） ProdID:" + _prod?.id);

            }
            else
            {
                RefreshMessage("获取工件，失败！", MessageState.Normal);
                Logger.Info("获取工件,失败（" + _equipment?.equipmentid + ")");
                orderMsg.Error = true;
                return orderMsg;
            }



            WoInfoViewModel.Matid = _prod.matid;
            WoInfoViewModel.Productid = _prod.productid;
            WoInfoViewModel.RepairCode = _prod.repaircode;
            WoInfoViewModel.SN = _prod.serial_number;
            WoInfoViewModel.ProcessCode = _prod.workseqgroup;
            WoInfoViewModel.ProcessDesc = _prod.workseqgroupdesc;

            RefreshMessage("工序开始！", MessageState.Normal);
            Logger.Info("工序开始！(" + _equipment?.equipmentid + "） ProdID:" + _prod?.id);
            orderMsg.Error = false;
            orderMsg.Cur_Prod = _prod;
            //orderMsg.Cur_Process = _curProcessRecord;
            orderMsg.barcode = ScanInfo;
            return orderMsg;
        }

        public void Heartbeat()
        {
            //connectionStatus = connectionStatus=="True"?"False":"True";
            connectionStatus = !connectionStatus ;
        }



        /// <summary>
        /// 处理“扭力扳手”请求
        /// </summary>
        public void Update_Process(List<scada_jobstep_record> jobsteps)
        {

            //Logger.Info("收到工步！(" + _equipment?.equipmentid + "）Count" + jobstepList.Count);
            foreach (var item in jobsteps)
            {
                if (item.prodid == 0)
                {
                    Logger.Info("(" + _equipment?.equipmentid + "）：该工步prodid为空，Tighteningid：" + item.tighteningid);
                    RefreshMessage("(" + _equipment?.equipmentid + "）：该工步prodid为空，Tighteningid：" + item.tighteningid, MessageState.Normal);
                    continue;
                }

                scada_product_info prod = SubmitDB.GetProdInfo(item.prodid);
                if (prod == null)
                {
                    Logger.Info("(" + _equipment?.equipmentid + "）：该工步prod为空，Tighteningid：" + item.tighteningid);
                    RefreshMessage("(" + _equipment?.equipmentid + "）：该工步prod为空，Tighteningid：" + item.tighteningid, MessageState.Normal);
                    continue;
                }
                item.matid = prod.matid;
                item.productid = prod.productid;
                item.repair = prod.repaircode;
                item.serial_number = prod?.serial_number;
                item.userid = _user.userid_int;//用户ID
                item.modifytime_dt = DateTime.Now;
                item.comment_str = prod.remark_str;

                SubmitDB.InsertorUpdateJobStepsRecord(item);

                
                prod.state_int = (int)State.Working;//生产中

                if (item.comment_str == "单枪")
                {
                    prod.state_int = (int)State.Finish;
                    _prod = null;
                }
                else
                {
                    if (item.batchstatus == 1)
                    {
                        if (prod.curtimes < prod.torquetimes)
                        {
                            prod.curtimes += 1;
                        }

                        if (prod.curtimes == prod.torquetimes)
                        {
                            prod.modifytime_dt = DateTime.Now;
                            prod.state_int = (int)State.Finish;
                            _prod = null;

                            RefreshMessage("(" + _equipment?.equipmentid + "）：工件完成！prod.serial_number：" + prod?.serial_number, MessageState.Sucess);
                            Logger.Info("(" + _equipment?.equipmentid + "）：工件完成！prod.serial_number：" + prod?.serial_number);
                        }
                    }
                }
                SubmitDB.Submit_Prod(prod);
                if (prod != null)
                {
                    RefreshJobStepUIByProdId(prod.id);
                }

            }

        }





        /// <summary>
        /// 清除工步
        /// </summary>
        private void ClearJobsteps()
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                SynchronizationContext.SetSynchronizationContext(new
                    DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
                SynchronizationContext.Current.Post(pl =>
                {
                    //里面写真正的业务内容
                    try
                    {
                        UI_Process.Clear();
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn($"刷新工序UI出错:{ex.Message}");
                    }
                }, null);
            });
        }


        /// <summary>
        /// 工步重打
        /// </summary>
        public bool RetryStep(out string msg)
        {
            msg = string.Empty;


            if (UI_Process.Any() && CurItem != null)
            {
                RetryJobStep = CurItem;
                return true;
            }
            else
            {
                msg = "没选中工步或工序为空！";
                return false;
            }



        }

        /// <summary>
        /// 工序重打
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool RetryProcess()
        {
            //msg = string.Empty;
            scada_process_record ProcessRecord = QueryData.GetProcessRecord(_curProcessRecord.id);
            if (UI_Process.Any())
            {
                ProcessRecord.state_int = (int)State.RetryProc;
                ProcessRecord.curtimes = 0;
                SubmitDB.Submit_ProcessRecrd(ProcessRecord);  //工序状态改为可重打状态
                SubmitDB.DeleteJobStepsByProcessRecordID(ProcessRecord.id);//删除该工序的所有工步
                Clear();
                RefreshMessage("开始重打当前工序！", MessageState.Sucess);
                return true;
            }
            else
            {
                RefreshMessage("当前工序为空！", MessageState.Sucess);
                return false;
            }


        }

        /// <summary>
        /// 客户端获取 当前子工序
        /// </summary>
        /// <returns></returns>
        public OrderMsg GetCurSubProcess()
        {
            var ordermsg = new OrderMsg();
            ordermsg.Cur_Process = _curProcessRecord;
            return ordermsg;
        }

        /// <summary>
        /// 客户端获取 当前工步
        /// </summary>
        /// <returns></returns>
        public OrderMsg GetRetryStep()
        {
            OrderMsg orderMsg = new OrderMsg();
            if (RetryJobStep != null)
            {

                orderMsg.CurStep = RetryJobStep;
                RetryJobStep = null;

            }
            return orderMsg;
        }

        /// <summary>
        /// KJF 20210323 新增
        /// 客户端 扭力缓存恢复
        /// </summary>
        public void TorqueRecordRecovery(List<TorqueParmas> TorqueParmas)
        {
            foreach (var item in TorqueParmas)
            {
                TorqueRecord(item);
            }
        }


        /// <summary>
        /// 记录扭力值
        /// </summary>
        /// <param name="torqueParmas"></param>
        public void TorqueRecord(TorqueParmas torqueParmas)
        {
            Params = ForeachClassProperties(torqueParmas);
            scada_torquerecord scada_Torquerecord = new scada_torquerecord();

            scada_Torquerecord.status = torqueParmas.TighteningStatus;
            scada_Torquerecord.torquestatus = torqueParmas.TorqueStatus;
            scada_Torquerecord.anglestatus = torqueParmas.AngleStatus;
            scada_Torquerecord.jobid = torqueParmas.JobID;
            scada_Torquerecord.vinnum = torqueParmas.VINNumber;
            scada_Torquerecord.torque = torqueParmas.Torque.ObjToDecimal();
            scada_Torquerecord.time = torqueParmas.TimeStamp.ObjToDate();
            scada_Torquerecord.batchcounter = torqueParmas.BatchCounter;
            scada_Torquerecord.batchsize = torqueParmas.BathSize;
            scada_Torquerecord.tighteningid = torqueParmas.TighteningID;
            scada_Torquerecord.torquefinaltarget = torqueParmas.TorqueFinalTarget;
            scada_Torquerecord.receivetime = DateTime.Now;//接收时间
            scada_Torquerecord.equipmentcode = torqueParmas.equipmentcode;
            scada_Torquerecord.userid = _user?.userid_int;//用户ID
            scada_Torquerecord.barcode = torqueParmas.barcode;
            scada_Torquerecord.sn = torqueParmas.sn;
            scada_Torquerecord.matid = torqueParmas.matid;
            scada_Torquerecord.woid = torqueParmas.woid;
            scada_Torquerecord.batchstatus = torqueParmas.BatchStatus;

            scada_Torquerecord.angle = torqueParmas.Angle?.ObjToDecimal();
            scada_Torquerecord.toolid = torqueParmas.Tools?.ObjToString();

            //Logger.Info("接收离线数据，vinnum："+ torqueParmas.VINNumber + " torqueParmas.equipmentcode:"
            //    + torqueParmas.equipmentcode+ "torqueParmas.sn:" + torqueParmas.sn);


            SubmitDB.Insert_TorqueRecord2(scada_Torquerecord);
        }

        /// <summary>
        /// 登陆
        /// </summary>
        private bool Login(string userCode)
        {
            _user = QueryData.GetUser(userCode);
            //临时代码
            //_user = new Sys_User_UserInfo();
            //_user.userid_int = userCode;


            if (_user != null)
            {
                Userid = _user.userid_int;
                IsLogin = true;

                return true;
            }
            return false;
        }



        /// <summary>
        /// 刷新信息
        /// </summary>
        /// <param name="content"></param>
        /// <param name="state"></param>
        private void RefreshMessage(string content, MessageState state)
        {
            Message.Content += DateTime.Now + "：" + content + "" + "\r";
            Message.State = (int)state;
        }





        /// <summary>
        /// 清除当前工件
        /// KJF 20210315 增加：点击“切换工件”时，清除文本框内容；
        /// </summary> 
        public void Clear()
        {
            //WoInfoViewModel.WO = string.Empty;
            //WoInfoViewModel.SN = string.Empty;
            //WoInfoViewModel.Code = string.Empty;
            //WoInfoViewModel.PlanQuantity = string.Empty;
            //WoInfoViewModel.MBOM = string.Empty;
            //WoInfoViewModel.JobstepVersion = string.Empty;
            //WoInfoViewModel.TechProcess = string.Empty;
            //WoInfoViewModel.ProcessCode = string.Empty;
            //WoInfoViewModel.ProcessDesc = string.Empty;

            WoInfoViewModel.Matid = string.Empty;
            WoInfoViewModel.SN = string.Empty;
            WoInfoViewModel.RepairCode = string.Empty;
            WoInfoViewModel.Productid = string.Empty;
            WoInfoViewModel.ProcessCode = string.Empty;
            WoInfoViewModel.ProcessDesc = string.Empty;


            ClearJobsteps();

            _barcode = "";
            _poid = "";
            _prod = null;
            _retryFlag = false;
            _processFlag = false;
            _curProcessRecord = null;
            _curProcessList?.Clear();

            //清除“服务端消息”
            Message.Content = "";
            //清除“客户端消息”
            ClientMsg = "";
        }





        /// <summary>
        /// KJF 20210324 新增
        /// 刷新JobStepRecord界面
        /// </summary>
        private void RefreshJobStepUIByProcessRecordId(int processRecordid)
        {

            //根据序列号刷新JobStepRecord界面
            List<scada_jobstep_record> JobStepRecords = QueryData.GetJobStepByProcessRecordID(processRecordid);
            ThreadPool.QueueUserWorkItem(delegate
            {
                SynchronizationContext.SetSynchronizationContext(new
                    DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
                SynchronizationContext.Current.Post(pl =>
                {
                    try
                    {
                        UI_Process.Clear();
                        //foreach (var item in JobStepRecords)
                        //{
                        //    if (item.state_int == (int)State.Finish)
                        //    {
                        //        UI_Process.Add(item);
                        //    }
                        //}

                        foreach (var item in JobStepRecords)
                        {

                            UI_Process.Add(item);

                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn($"刷新工序UI出错:{ex.Message}");
                    }
                }, null);
            });
        }


        /// <summary>
        /// KJF 20210324 新增
        /// 刷新JobStepRecord界面
        /// </summary>
        private void RefreshJobStepUIByProdId(int id)
        {

            //根据序列号刷新JobStepRecord界面
            List<scada_jobstep_record> JobStepRecords = QueryData.GetJobStepByProdID(id);
            ThreadPool.QueueUserWorkItem(delegate
            {
                SynchronizationContext.SetSynchronizationContext(new
                    DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
                SynchronizationContext.Current.Post(pl =>
                {
                    try
                    {
                        UI_Process.Clear();
                        //foreach (var item in JobStepRecords)
                        //{
                        //    if (item.state_int == (int)State.Finish)
                        //    {
                        //        UI_Process.Add(item);
                        //    }
                        //}

                        foreach (var item in JobStepRecords)
                        {

                            UI_Process.Add(item);

                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn($"刷新工序UI出错:{ex.Message}");
                    }
                }, null);
            });
        }




        /// <summary>
        /// 采集的参数转为列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        private List<BaseObject> ForeachClassProperties<T>(T model)
        {
            List<BaseObject> parmas = new List<BaseObject>();
            Type t = model.GetType();
            PropertyInfo[] PropertyList = t.GetProperties();
            foreach (PropertyInfo item in PropertyList)
            {
                var value = (item.GetValue(model, null) == null ? string.Empty : item.GetValue(model, null).ToString());
                BaseObject baseObject = new BaseObject();
                baseObject.FildName = item.Name;
                baseObject.FildValue = value;
                parmas.Add(baseObject);
            }
            return parmas;
        }





        #region 属性

        /// <summary>
        /// 显示扫码信息
        /// </summary>
        public string ScanMsg
        {
            get { return _woSn; }
            set
            {
                if (value != _woSn)
                {

                    _woSn = value;
                    OnPropertyChanged(nameof(ScanMsg));
                }
            }
        }
        private string _woSn;
        /// <summary>
        /// 工位号
        /// </summary>
        public string WorkbinName
        {
            get => _WorkbinName;
            set
            {
                if (value != _WorkbinName)
                {
                    _WorkbinName = value;
                    OnPropertyChanged(nameof(WorkbinName));
                }
            }
        }
        private string _WorkbinName;



        /// <summary>
        /// 连接状态
        /// </summary>
        public bool connectionStatus 
        {
            get => _connectionStatus;
            set
            {
                if (value != _connectionStatus)
                {
                    _connectionStatus = value;
                    OnPropertyChanged(nameof(connectionStatus));
                }
            }
        }
        private bool _connectionStatus  = true;















        private string _UserName;

        public string UserName
        {
            get { return _UserName; }
            set
            {
                if (value != _UserName)
                {
                    _UserName = value;
                    OnPropertyChanged(nameof(UserName));
                }
            }
        }

        /// <summary>
        /// 工位号
        /// </summary>
        public string Userid
        {
            get => _Userid;
            set
            {
                if (value != _Userid)
                {
                    _Userid = value;
                    OnPropertyChanged(nameof(Userid));
                }
            }
        }
        private string _Userid;



        /// <summary>
        /// 当前SN
        /// </summary>
        public string CurSn
        {
            get { return _CurSn; }
            set
            {
                if (value != _CurSn)
                {
                    _CurSn = value;
                    OnPropertyChanged(nameof(CurSn));
                }
            }
        }
        private string _CurSn;
        /// <summary>
        /// 当前派工件号
        /// </summary>
        public string DisidNo { get; private set; }
        /// <summary>
        /// 当前工步编码
        /// </summary>
        public string CurStepCode
        {
            get;
            private set;
        }
        /// <summary>
        /// 作业指导书名
        /// </summary>
        public string IntrodName
        {
            get { return _IntrodName; }
            set
            {
                if (value != _IntrodName)
                {
                    _IntrodName = value;
                }
            }
        }
        private string _IntrodName;

        /// <summary>
        /// 工序列表
        /// </summary>
        public List<string> DisqueList
        {
            get => _disqueList ?? (_disqueList = new List<string>());
            set
            {
                if (_disqueList != value)
                {
                    _disqueList = value;
                    OnPropertyChanged(nameof(DisqueList));
                }
            }
        }
        private List<string> _disqueList;


        /// <summary>
        /// 当前工步序号
        /// </summary>
        public int CurIndex
        {
            get; set;
        }
        /// <summary>
        /// 当前用户名
        /// </summary>
        public string User
        {
            get { return _User; }
            set
            {
                if (value != _User)
                {
                    _User = value;
                    OnPropertyChanged(nameof(User));
                }
            }
        }
        private string _User;
        /// <summary>
        /// 过站的物料SN
        /// </summary>
        public string MatSn
        {
            get { return _MatSn; }
            set
            {
                if (value != _MatSn)
                {
                    _MatSn = value;
                    OnPropertyChanged(nameof(MatSn));
                }
            }
        }
        private string _MatSn;
        /// <summary>
        /// 工步信息的当前所行
        /// </summary>
        public scada_jobstep_record CurItem
        {
            get => _curItem;
            set
            {
                if (_curItem != value)
                {
                    _curItem = value;
                }
            }
        }
        private scada_jobstep_record _curItem;
        /// <summary>
        /// 重打工步信息
        /// </summary>
        public scada_jobstep_record RetryJobStep { get; private set; }

        /// <summary>
        /// 当前表格所选行的序号
        /// </summary>
        public int GridIndex { get; private set; }




        private ObservableCollection<scada_jobstep_record> _ui_Process = new ObservableCollection<scada_jobstep_record>();
        /// <summary>
        /// 过滤后要显示的工步信息表信息
        /// </summary>
        public ObservableCollection<scada_jobstep_record> UI_Process
        {
            get { return _ui_Process; }
            set
            {
                _ui_Process = value;
                if (_ui_Process != value)
                {
                    OnPropertyChanged(nameof(UI_Process));
                }
            }
        }
        private ObservableCollection<scada_jobstep_record> _detailStep = new ObservableCollection<scada_jobstep_record>();
        /// <summary>
        /// 详细信息表的信息
        /// </summary>
        public ObservableCollection<scada_jobstep_record> DetailStep
        {
            get { return _detailStep; }
            set
            {
                _detailStep = value;
                if (_detailStep != value)
                {
                    OnPropertyChanged(nameof(DetailStep));
                }
            }
        }

        private ObservableCollection<scada_jobstep_record> _curStep = new ObservableCollection<scada_jobstep_record>();
        /// <summary>
        /// 当前做的工步的信息
        /// </summary>
        public ObservableCollection<scada_jobstep_record> CurStep
        {
            get { return _curStep; }
            set
            {
                _curStep = value;
                if (_curStep != value)
                {
                    OnPropertyChanged(nameof(_curStep));
                }
            }
        }


        public WoInfoViewModel WoInfoViewModel { get; set; }
        /// <summary>
        /// 当前工件的SN总数量
        /// </summary>
        public int SumCount
        {
            get { return _SumCount; }
            set
            {
                if (value != _SumCount)
                {
                    _SumCount = value;
                    OnPropertyChanged(nameof(SumCount));
                }
            }
        }
        private int _SumCount;
        /// <summary>
        /// 当前完成进度
        /// </summary>
        public Decimal CurCount
        {
            get { return _CurCount; }
            set
            {
                if (value != _CurCount)
                {
                    _CurCount = value;
                    OnPropertyChanged(nameof(CurCount));
                }
            }
        }
        private Decimal _CurCount;
        /// <summary>
        /// 当前所用时间
        /// </summary>
        public Decimal CurTime
        {
            get { return _CurTime; }
            set
            {
                if (value != _CurTime)
                {
                    _CurTime = value;
                    OnPropertyChanged(nameof(CurTime));
                }
            }
        }
        private Decimal _CurTime;
        /// <summary>
        /// 工序任务用时
        /// </summary>
        public float SumTime
        {
            get { return _SumTime; }
            set
            {
                if (value != _SumTime)
                {
                    _SumTime = value;
                    OnPropertyChanged(nameof(SumTime));
                }
            }
        }
        private float _SumTime;
        /// <summary>
        /// 耗时字符串
        /// </summary>
        public String ConsTime
        {
            get { return _ConsTime; }
            set
            {
                if (value != _ConsTime)
                {
                    _ConsTime = value;
                    OnPropertyChanged(nameof(ConsTime));
                }
            }
        }
        private String _ConsTime;
        /// <summary>
        /// 任务进度字符串
        /// </summary>
        public String TaskProgre
        {
            get { return _TaskProgre; }
            set
            {
                if (value != _TaskProgre)
                {
                    _TaskProgre = value;
                    OnPropertyChanged(nameof(TaskProgre));
                }
            }
        }
        private String _TaskProgre;

        public Message Message { get; set; }
        /// <summary>
        /// 工序重打
        /// </summary>
        public bool RetryProceTag { get; set; }

        private string _ClientMsg;
        /// <summary>
        /// 接收客户端的信息
        /// </summary>
        public string ClientMsg
        {
            get { return _ClientMsg; }
            set
            {
                if (value != _ClientMsg)
                {
                    _ClientMsg = value;
                    OnPropertyChanged(nameof(ClientMsg));
                }
            }
        }

        private List<BaseObject> _params;
        /// <summary>
        /// 扭力枪参数
        /// </summary>
        public List<BaseObject> Params
        {
            get { return _params; }
            set
            {
                if (value != _params)
                {
                    _params = value;
                    OnPropertyChanged(nameof(Params));
                }
            }
        }
        #endregion



    }

}